package com.apestech.framework.dictionary.lib;

import com.apestech.framework.db.SqlResultSet;
import com.apestech.framework.json.JSON;
import com.apestech.framework.json.JSONObject;
import com.apestech.framework.stream.callback.ReadRowHander;

/**
 * @author hup
 * @create 2018-08-16-16:29
 */
public class ProcRowHander implements ReadRowHander {
    private SqlResultSet rs;

    public ProcRowHander(SqlResultSet rs){
        this.rs=rs;
    }

    @Override
    public String processRow(int index) throws Exception {
        JSONObject map=new JSONObject();
        map.put("COLUMN_NAME", rs.getObject("COLUMN_NAME"));
        String TYPE_NAME=rs.getString("TYPE_NAME");
        String COLUMN_TYPE=rs.getString("COLUMN_TYPE");
        if("VARCHAR2".equals(TYPE_NAME)){
            map.put("CLASSNAME", "java.lang.String");
        } else if("NUMBER".equals(TYPE_NAME)){
            map.put("CLASSNAME", "java.math.BigDecimal");
        } else if("DATE".equals(TYPE_NAME)){
            map.put("CLASSNAME", "java.sql.Timestamp");
        }
        if("1".equals(COLUMN_TYPE)){
            map.put("TYPE", "in");
        } else if("2".equals(COLUMN_TYPE)){
            map.put("TYPE", "inout");
        } else if("4".equals(COLUMN_TYPE)){
            map.put("TYPE", "out");
        }
        map.put("COLUMN_TYPE", COLUMN_TYPE);
        map.put("TYPE_NAME", TYPE_NAME);
        map.put("PROCEDURE_NAME", rs.getString("PROCEDURE_NAME"));
        String txt= JSON.toJSONString(map);
        return txt;
    }
}
